<?php
namespace app\logic;

use app\common\corelib\CacheHelper;
use app\models\Device;
use yii\db\Query;



class DeviceLogic
{

    public function getDevice($device_qrcode){
        return Device::find()
            ->select('d.*,s.shop_id,s.shop_name,u.phone,m.manager_name')
            ->from('{{%device}} d')
            ->leftJoin('{{%shop}} s','s.shop_id=d.shop_id')
            ->leftJoin('{{%manager}} m','m.shop_id=s.shop_id AND m.on_work=1')
            ->leftJoin('{{%user}} u','u.user_id=m.user_id')
            ->where("d.device_qrcode=$device_qrcode")
            ->asArray()->one();
    }

    public function getDeviceById($device_id){
        return Device::find()->where(['device_id'=>$device_id])->asArray()->one();
    }

}
